package com.orhon.smartcampus.modules.systemctl.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.*;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "systemctl_widgets", schema = "smartcloud", catalog = "")
public class Widgets {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;
    @Column(name = "title", nullable = false)
    private String title;
    @Column(name = "name", nullable = false, length = 191)
    private String name;
    @Column(name = "type", nullable = false, length = 191)
    private String type;
    @Column(name = "meta", nullable = true)
    private String meta;
    @Column(name = "clients", nullable = false)
    private String clients;
    @Column(name = "status", nullable = true)
    private Integer status;
    @Column(name = "created_at", nullable = false)
    private Date createdAt;
    @Column(name = "updated_at", nullable = true)
    private Date updatedAt;
    @Column(name = "deleted_at", nullable = true)
    private Date deletedAt;
    @ManyToOne
    @JoinColumn(name = "menu_id", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
    @Where(clause = "ISNULL(deleted_at)")
    private Menus systemctlMenusByMenuId;
    @ManyToOne
    @JoinColumn(name = "module_id", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
    @Where(clause = "ISNULL(deleted_at)")
    private Modules systemctlModulesByModuleId;

    @ManyToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
    @JoinTable(name = "systemctl_api_page_relation",
            joinColumns = { @JoinColumn(name = "menu_id")},
            inverseJoinColumns = { @JoinColumn(name = "api_id")})
    List<Apis> apis;

}
